package validate;

import model.MomentComment;
import model.Recipe;
import model.RecipeComment;
import util.AppUtil;
import constant.Msg;

public class CommentValidate {
	public static String get(String recipeId){
		if (recipeId==null|| !AppUtil.isInteger(recipeId)) {
			return Msg.ERROR_PARA_TYPE;
		}
		if(Recipe.dao.findById(recipeId)==null)
			return Msg.ERROR_ID_UNEXISTED;
		return null;
	}
	public static String post(RecipeComment comment) {
		String userId=comment.get("user_id");
		String recipeId=comment.get("recipe_id");
		String content=comment.get("content");
		System.out.println("content"+content);
		if (userId==null||recipeId==null||content==null) return Msg.ERROR_PARA_NUM;
		
		if (!AppUtil.isInteger(recipeId)||!AppUtil.isInteger(userId))return Msg.ERROR_PARA_TYPE;
		
		return null;
	}
	public static String post(MomentComment comment) {
		String userId=comment.get("user_id");
		String momentId=comment.get("moment_id");
		String content=comment.get("content");
		if (userId==null||momentId==null||content==null) return Msg.ERROR_PARA_NUM;
		
		if (!AppUtil.isInteger(momentId)||!AppUtil.isInteger(userId))return Msg.ERROR_PARA_TYPE;
		
		return null;
	}
	public static String delete(String commentId,int userId){
		if(commentId==null||!AppUtil.isInteger(commentId))return Msg.ERROR_PARA_TYPE;
		RecipeComment comment =RecipeComment.dao.findById(commentId);
		if(comment==null)
			return Msg.ERROR_ID_UNEXISTED;
		else if((int)comment.get("user_id")!=userId){
//			System.out.println(comment.get("user_id")+userId);
			return Msg.ERROR_NO_PERMISSION;
		}
			
		return null;
	}
}
